home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 138
/
Volume 138 Aug 19 2011 - Damaged.iso
/
Games
/
shadez.swf
/
scripts
/
STC9
/
System
/
CProfiler.as
< prev
Wrap
Text File
|
2011-08-19
|
15KB
|
436 lines
package STC9.System
{
import STC9.String.CString;
import flash.system.System;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.getTimer;
public class CProfiler extends TextField
{
static var mNumberOfSamples:Number = 30;
private static const mAllowProfiles:Boolean = true;
private static var SLOWEXPIRETIME:uint = 5 * 1000;
private static const mAllowDebugs:Boolean = true;
private static var _this:CProfiler;
private var mSamples:Array;
private var mProfiles:Object;
private var mLastTimeStamp:Number;
private var mAlign:String;
private var mDebugs:Object;
public var mMode:String = "normal";
private var mSampleTotalTime:Number;
public var mDebug:String = "";
public function CProfiler(param1:String = "RIGHT", param2:String = "normal")
{
mDebug = "";
mMode = "normal";
_this = this;
super();
mAlign = param1;
this.defaultTextFormat = new TextFormat("_sans",9,0);
this.text = "FPS: ";
this.background = true;
this.backgroundColor = 15658734;
this.border = false;
this.x = 0;
this.y = 0;
this.autoSize = TextFieldAutoSize.LEFT;
mMode = param2;
Reset();
}
public static function Show() : void
{
_this.visible = true;
}
public static function StartProfile(param1:String) : void
{
var _loc2_:Object = null;
if(true)
{
§§push(mActive);
if(true)
{
if(!§§pop())
{
if(true)
{
return;
}
}
else
{
§§push(mAllowProfiles);
if(true)
{
§§push(!§§pop());
if(!§§pop())
{
}
addr32:
if(§§pop())
{
return;
}
_loc2_ = !!_this.mProfiles[param1] ? _this.mProfiles[param1] : {
"mClear":true,
"mSlowTime":0,
"mSlowTimeExpires":getTimer() + SLOWEXPIRETIME
};
§§goto(addr34);
}
§§pop();
§§goto(addr32);
§§push(!_this);
}
addr34:
if(true)
{
if(_loc2_.mClear)
{
if(true)
{
_loc2_.mTotalTime = 0;
if(true)
{
_loc2_.mClear = false;
addr80:
_loc2_.mStartTimer = getTimer();
}
§§goto(addr80);
}
_this.mProfiles[param1] = _loc2_;
§§goto(addr96);
}
§§goto(addr80);
}
addr96:
return;
}
§§goto(addr32);
}
§§goto(addr39);
}
public static function Hide() : void
{
if(true)
{
_this.visible = false;
}
}
public static function StopProfile(param1:String, param2:Boolean = false) : Number
{
var _loc3_:uint = 0;
var _loc4_:Object = null;
if(!mActive)
{
return 0;
}
if(!mAllowProfiles || !_this || !_this.mProfiles[param1])
{
return 0;
}
_loc3_ = getTimer();
(_loc4_ = _this.mProfiles[param1]).mLocalTime = _loc3_ - _loc4_.mStartTimer;
if(_loc3_ > _loc4_.mSlowTimeExpires)
{
_loc4_.mSlowTime = _loc4_.mLocalTime;
_loc4_.mSlowTimeExpires = _loc3_ + SLOWEXPIRETIME;
}
_loc4_.mSlowTime = _loc4_.mLocalTime > _loc4_.mSlowTime ? _loc4_.mLocalTime : _loc4_.mSlowTime;
_loc4_.mTotalTime = !!param2 ? _loc4_.mTotalTime + _loc4_.mLocalTime : _loc4_.mLocalTime;
return _loc4_.mLocalTime;
}
public static function Reset() : void
{
if(true)
{
_this.mSamples = new Array();
if(true)
{
_this.mSampleTotalTime = 0;
_this.mProfiles = new Object();
}
_this.mDebugs = new Object();
}
}
public static function AddDebug(param1:String, param2:String) : void
{
if(mActive && _this && mAllowDebugs)
{
_this.mDebugs[param1] = param2;
}
}
public static function get mActive() : Boolean
{
return _this.parent != null;
}
public static function RemoveDebug(param1:String) : void
{
if(true)
{
§§push(Boolean(mActive));
if(Boolean(mActive))
{
§§pop();
if(true)
{
addr29:
if(_this && mAllowDebugs)
{
}
§§goto(addr47);
}
delete _this.mDebugs[param1];
addr47:
return;
}
}
§§goto(addr29);
}
public static function ToggleMode() : void
{
if(true)
{
if(_this.mMode == "normal")
{
if(true)
{
_this.mMode = "fpsonly";
if(false)
{
addr37:
}
}
}
else if(_this.mMode == "fpsonly")
{
_this.mMode = "off";
§§goto(addr37);
}
else
{
_this.mMode = "normal";
}
§§push(_this);
§§push(_this.mMode == "off");
if(true)
{
§§push(!§§pop());
}
§§pop().visible = §§pop();
}
}
public static function ToggleVisible() : void
{
_this.visible = !_this.visible;
}
public function Dispose() : void
{
}
function Clone() : CProfiler
{
return undefined;
}
private function Pad(param1:String, param2:Number) : String
{
while(param1.length < param2)
{
param1 = " " + param1;
}
return param1;
}
private function GetFPS(param1:Number) : Number
{
var _loc2_:* = undefined;
_loc2_ = 1;
return Math.round(1000 / param1 * _loc2_) / _loc2_;
}
public function Update(param1:Boolean = false) : void
{
var _loc2_:Number = NaN;
var _loc3_:Number = NaN;
var _loc4_:* = null;
var _loc5_:Array = null;
var _loc6_:Object = null;
if(!mActive)
{
return;
}
_loc2_ = getTimer();
if(mLastTimeStamp)
{
_loc3_ = _loc2_ - mLastTimeStamp;
mSampleTotalTime += _loc3_;
mSamples.push(_loc3_);
loop0:
do
{
if(mSamples.length > mNumberOfSamples)
{
continue;
}
if(true)
{
this.text = "FPS: " + CString.Pad(GetFPS(mSampleTotalTime / mSamples.length),"0",3);
if(true)
{
this.text += " (" + Math.round(System.totalMemory / (1024 * 1024)) + "mb)";
if(true)
{
if(mMode == "normal")
{
if(true)
{
_loc5_ = new Array();
var _loc7_:* = 0;
if(true)
{
var _loc8_:* = mProfiles;
if(true)
{
loop1:
while(true)
{
§§push(§§hasnext(_loc8_,_loc7_));
if(true)
{
if(§§pop())
{
_loc4_ = §§nextname(_loc7_,_loc8_);
continue;
}
if(true)
{
if(true)
{
_loc7_ = 0;
}
_loc8_ = mDebugs;
while(true)
{
§§push(§§hasnext(_loc8_,_loc7_));
break loop1;
}
addr202:
}
if(_loc5_.length)
{
this.text += "\n-----------------------------------";
_loc5_.sort();
this.text += "\n" + _loc5_.join("\n");
addr227:
mLastTimeStamp = _loc2_;
_loc7_ = mAlign.toUpperCase();
if(true)
{
if("LEFT" === _loc7_)
{
§§push(0);
if(true)
{
}
}
else
{
§§push("RIGHT" === _loc7_ ? 1 : 2);
}
switch(§§pop())
{
case 0:
x = 0;
addr235:
break;
case 1:
x = stage.stageWidth - width;
addr243:
}
addr267:
if(param1)
{
addr269:
for(_loc4_ in mProfiles)
{
mProfiles[_loc4_].mClear = true;
}
break loop0;
}
break loop0;
}
§§goto(addr261);
}
§§goto(addr227);
}
break;
}
while(true)
{
if(§§pop())
{
_loc4_ = §§nextname(_loc7_,_loc8_);
_loc5_.push(_loc4_ + ":" + mDebugs[_loc4_]);
continue;
}
§§goto(addr204);
}
addr171:
}
while(true)
{
_loc6_ = mProfiles[_loc4_];
_loc5_.push(_loc4_ + ":" + _loc6_.mLocalTime + (_loc6_.mTotalTime != _loc6_.mLocalTime && _loc6_.mTotalTime != 0 ? " (" + _loc6_.mTotalTime + ")" : " [" + _loc6_.mSlowTime + "]"));
§§goto(addr171);
}
}
§§goto(addr205);
}
§§goto(addr235);
}
§§goto(addr227);
}
§§goto(addr243);
}
§§goto(addr267);
}
§§goto(addr269);
}
while(mSampleTotalTime -= mSamples.shift(), true);
return;
}
§§goto(addr227);
}
}
}